﻿/*******************************************************
* Copyright (c) 2018-2088, By XuXiang all rights reserved.
*
* FileName: BasicModuleConfig.h
* Summary: 基础模块配置。
*
* Author: XuXiang
* Date: 2024-05-11 22:35
*******************************************************/

#ifndef __BasicModuleConfig_h__
#define __BasicModuleConfig_h__

#include "ModuleConfig.h"
#include "Wrap/ConstWrap.h"
#include "Wrap/RoleWrap.h"

namespace Competition
{
	//常量配置
	class ConstConfig : public ConstWrap {};
	CONFIG_MAP(ConstConfig);

	//角色配置
	class RoleConfig : public RoleWrap {};
	CONFIG_MAP(RoleConfig);

	//基础模块配置
	class BasicModuleConfig : public ModuleConfig
	{
	public:
		BasicModuleConfig();
		virtual ~BasicModuleConfig();

		virtual const char* GetName()const { return "BasicModuleConfig"; }

		//获取常量配置
		inline ConstConfig* GetConstConfig(const string& name) { auto itr = m_NameToConst.find(name); return itr == m_NameToConst.end() ? NULL : itr->second; }

		//获取常量值1
		inline int GetConstValue1(const string& name) { ConstConfig *cfg = GetConstConfig(name); return cfg == NULL ? 0 : cfg->value1; }

		//获取常量值2
		inline int GetConstValue2(const string& name) { ConstConfig *cfg = GetConstConfig(name); return cfg == NULL ? 0 : cfg->value2; }

		//获取常量值3
		inline int GetConstValue3(const string& name) { ConstConfig *cfg = GetConstConfig(name); return cfg == NULL ? 0 : cfg->value3; }

		//获取常量字符串
		inline string GetConstString(const string& name) { ConstConfig *cfg = GetConstConfig(name); return cfg == NULL ? string() : cfg->value_str; }

		//获取角色配置
		inline RoleConfig* GetRoleConfig(int id) { auto itr = m_Roles.find(id); return itr == m_Roles.end() ? NULL : itr->second; }

	protected:

		virtual void OnInit();
		virtual void OnRelease();

	private:

		//常量配置
		ConstConfigMap m_Consts;

		//属性名称到类型
		map<string, ConstConfig*> m_NameToConst;

		//角色配置
		RoleConfigMap m_Roles;
	};
}

#endif
